#include "MenuManager.h"
#include "ServiceProvider.h"

//menus
#include "StartingMenu.h"
#include "LoadMenu.h"
#include "MainMenu.h"

MenuManager::MenuManager(ServiceProvider* sp, GameControls* gc): sp_(sp), gc_(gc) {
	starting_menu_ = new StartingMenu(this);
	main_menu_ = new MainMenu(this);
	load_menu_ = new LoadMenu(this);

	current_menu_ = starting_menu_;
}

MenuManager::~MenuManager() {
	delete starting_menu_;
	delete main_menu_;
	delete load_menu_;
}

void MenuManager::PushMenu(Menu* menu) {
	menu_stack_.push_back(current_menu_);
	SetMenu(menu);
}

void MenuManager::PopMenu() {
	if (menu_stack_.empty()) {
		if (current_menu_) {
			current_menu_->OnExit();
		}
		current_menu_ = 0;
	} else {
		SetMenu(menu_stack_.back());
		menu_stack_.pop_back();
	}
}

void MenuManager::SetMenu(Menu *menu) {
	if (current_menu_)
		current_menu_->OnExit();
	current_menu_ = menu;
	if (current_menu_)
		current_menu_->OnEnter();
}
